url = '/:slug|[a-z0-9\-]+-p-\d+.html$'
description = '产品内容页模板'
layout = 'default'
==
function onStart(){
	$slugArr = explode('-', str_replace('.html', '', $this->param('slug')));
	$id = array_pop($slugArr);
	$condition = ['id'=>$id];
	$product = App::make('Jason\Ccshop\Controllers\Products')->getProduct($condition);
	if ($product) {
	    if(get('preview')!='true'){
	      if($product['status'] != 'instock'){
	        if($product['status'] != 'stockout'){
	        return redirect('/404');
	         }       
	       } 
	    }
 
	    $this['wishlistClass']='';
        //$this['is_user_wish'] = false;
        if($this->user){
           $is_user_wish = Illuminate\Support\Facades\DB::table('cc_wishlists')->where(['uid'=>$this->user->id,'product_id'=>$product['id']])->select('id')->get();
           if($is_user_wish){
             $this['wishlistClass']='active';
             //$this['is_user_wish'] = true;
           }
        }
		$featureImageCount = count($product['feature_image']);
		if($featureImageCount < 9){
			preg_match_all('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$product['content'], $match);
			$contentImages = isset($match[2]) ? $match[2] : [];
			if(!empty($contentImages)){
				foreach($contentImages as $contentImage){
					if(stripos($contentImage,'.png')===false){
						$product['feature_image'][] = ['title' => '', 'path' => $contentImage];
					}
					if(count($product['feature_image'])==9){
						break;
					}
				}
			}
		}
		$this['product'] = $product;
	} else {
		return redirect('/404');
	}

}
==
{% set reviews = catalog.getReviews(product.id) %}
{% put page_title %} {{product.name}} -{{ domain|slice(7) }}{% endput %}
{% put meta_keywords %} {{ product.meta_keywords }}{% endput %}
{% put meta_description %}{{ product.meta_description }} {% endput %}

<div class="product_content">
	<!-- breadcrumbs -->
	{% partial 'common/breadCrumb' product=product categories=product.categories %}
	<!-- breadcrumbs end -->
	<div class="productCont">
		<div class="container">
		<form action="#" method="POST" id="product_addtocart_form">
			<div class="productItemData">
				<div class="fl">
					<ul id="example3">
						{% for key, img in product.feature_image %}
						<li {% if loop.index == 1 %} class="active"{% endif %}>
							<img class="etalage_thumb_image" src="{{ img.path }}" />
							<img class="etalage_source_image" src="{{ img.path }}" />
						</li>
						{% endfor %}
					</ul>
				</div>
				
				<div class="fr">

					<p class="mb10"><img src="{{ 'assets/img/new.png'|theme }}" alt="" width="36" height="17"></p>
	
					<h2 class="productHead mb15">{{ product.name }}</h2>
					<p class="productPrice mb15"><span>{{ product.price|formatPrice }}</span>（税込）
					<br>
						<s>{{ product.list_price|formatPrice }}</s>（税込）&nbsp; {{ product.discount}} OFF
					<br>
						ポイント:	 {{ getProductPoint(product.id) }}
					</p>
				<div class="product_id">
            			<h2>商品番号：<span>{{ product.id }}</span></h2>
            			<div class="availability {% if product.status == 'instock' %}in-stock{% else %}out-of-stock{% endif %}">
							<span>{{ ('jason.ccshop::lang.product.status.' ~ product.status)|trans }}</span></div>
            			<span class="reviewStar size2 star{{ reviews.rating_stat.avg | round }}"></span>
           				 <a href="#reviews" class="reviewsShow">レビュー / <b>{{ reviews.total }}</b> 件</a>
         		 </div>
          	
					<div class="option-element">
						{% for option in product.options %}
							
							<div class="changeBox mb15">
					            <h2> {{option.name}} :   <span class="changeText"></span></h2>
				            	<div class="color_change">
				            		{% if option.values is iterable %}
				            			{% for val in option.values %}
											<label class="radio-inline">
						                		<input type="radio" name="ProductOption[{{ option.id }}]" {% if loop.index ==  1 %}checked{% endif %} class="radio" value="{{val.id}}">
						                		{% if val.thumb.path %}
							                        <span>
							                       		<img src="{{val.thumb.path}}" alt="{{ val.name }}" title="{{ val.name }}"  width="62" height="72">
							                       	</span>
						                       	{% else %}
						                       		<span> <b class="text">{{ val.name }}</b> </span>
						                       	{% endif %}
						                    </label>
				            			{% endfor %}
				            		{% endif %}				                    
				                    
				                </div>
							</div>	

						{% endfor %}							
						
						<div class="changeNum">
							<h2> 個数:  <input type="text" class="changeNumIpt" value="1" name="qty"></h2>
			                <p class="mt10" style="color: #ef98a8;"><b>※≥5点送料無料</b></p>
						</div>
						
						<div class="add-cart-box" data-request-data="product:'{{ product.id }}'">
							{% if product.status == 'instock' %}
							<button class="btn-add-mybag blueBtn1" id="onAddToCart" data-request="onAddToCart" data-request-redirect="{{ ''|page }}" data-request-update="'common/shopping-cart':'.min_cart'">
								ショッピングバッグに入れる
							</button>
							{% else %}
								<button class="btn-add-mybag blueBtn1" disabled style="background: #ccc;">在庫切れ</button>
							{% endif %}	
							
						</div>

						<button class="btn-add-favorite bd_none {{wishlistClass}}" data-request="onAddToWishlist" data-request-data="key: {{ product.id }}">
								お気に入りに追加する
								<span class="wishNum ">{{  product.custom_fields['wish_total']}}</span>
							</button>
						
					</div>
				</div>				
			</div>
		</form>	
			<br style="clear: both;">
			<div>
				
				 <ul class="text_switch" id="reviews">
        			<li class="active">商品詳細</li>
        			<li>レビュー / <b>{{ reviews.total }}</b> 件</li>
      			</ul>
				<div class="review_content">
					<div class="contentText">
			            <p style="margin: 5px 0;"><b>商品説明：</b></p>
			            <table width="600" border="1" class="contentText_table">
			                <tbody>                    
			                    {% for key, f in product.features %}
			                        <tr>
			                            <td style="padding:3px 5px;">{{ f.name }}</td>
			                            <td style="padding:3px 5px;">{{ f.value_name }}</td>
			                        </tr>
			                    {% endfor %}
			                </tbody>
			            </table>
        				
							<div class="text_content">
								{{ product.content|raw }}
							</div>
				        	<div class="text_content">
				          				{{ form_ajax('onPushReview') }}
				         				<input type="hidden" name="product" value="{{ product.id }}">
				          				<input type="hidden" name="name" value="{{ user.name }}">
				          				<input type="hidden" name="title" value="レビュー">
				          				<label class="label-wide" for="review_field">レビュー <em>*</em></label>
				          				<textarea class="required-entry" rows="3" cols="5" id="review_field" name="content" style="height:100px;"></textarea>          
				         		<div class="review_btm">
				           				 <input type="radio" class="radio" value="1" id="Quality_1" name="rating">1*
				           				 <input type="radio" class="radio" value="2" id="Quality_2" name="rating">2*
				            			<input type="radio" class="radio" value="3" id="Quality_3" name="rating">3*
				           				 <input type="radio" class="radio" value="4" id="Quality_4" name="rating">4*
				            			<input type="radio" class="radio" value="5" id="Quality_5" name="rating">5*
				            			{% if user.email%}
				            			<button class="button submit" title="Submit Review" type="submit" ><span>提出する</span></button>
				           				 {% else %}
				            				<a href="{{ 'account/login'|page }}">登録する後で</a>
				            			<button class="button submit" disabled style="background:#eee;border:1px #ddd solid;color:#000;float: right;height: 35px;" ><span>提出する</span></button>
				            			{% endif %}
				         		</div>
				          					{{ form_close() }}
				         		 <div class="review_cont">
				           				 <label class="label-wide">お客様のレビュー</label>
				           				<div class="reviewArea_header">
				             				<div>
				                  				<b>総合評価</b>
				                  				<span class="reviewStar size2 star{{ reviews.rating_stat.avg | round }}"></span>
				             				 </div>
				              				<div class="cnt">
				                  				<b>({{ reviews.total }})</b>レビュー
				              				</div>
				           				 </div>
				           						 {% for key, review in reviews %}
				            			<div class="review_text">
				              				<p class="text_color">{{ getReviewsName(review.name) }} <b>{{ review.created_at | date("Y/m/d") }}</b></p>
				              				<p>{{ review.content }}</p>
				            			</div>
				            				{% endfor %}
				            			<div class="actions" style="margin-top:10px;">
				              				<div class="pager">
				                				<div class="pages">
				                  					{{ reviews.fragment('reviews').render()|raw }}
				                				</div>
				              				</div>
				            		</div>
				          		</div>
				        	</div>
				      </div>
				</div>
			</div>
			{% partial 'catalog/product-recommend' pid=product.id code='pc-product-related' %}
		</div>
	</div>
</div>
{% put scripts %}
	<script>
		$(function(){
			$("#example3").find("li .etalage_thumb_image").each(function(i,item){
				 var img = new Image();
		        img.src = $(item).attr("src");
		         var intv = window.setInterval(function(){
		            if(img.complete){
		                var imgHeight = img.height;
		                var imgWidth = img.width;
		                if( Math.abs(1-(imgWidth/imgHeight)) > 0.3 ){
		                    $(item).parents("li").remove()    
		                }
		                clearInterval(intv);
		            }
		        }, 5);
			})
		    var t = setTimeout(function(){  //为了删除过高图片延迟执行，无奈之举
       			 zoom();
			},300);
		})
		var zoom = function(){
		    if($('#example3') != null || $('#example3') != "underline"){
		        $('#example3').etalage({
		            thumb_image_width: 450,
		            thumb_image_height: 450,
		            source_image_width: 1200,
		            source_image_height: 1200,
		            zoom_area_width: 550,
		            zoom_area_height: 550,
		            zoom_area_distance: 5,
		            small_thumbs: 5,
		            smallthumb_inactive_opacity: 0.6,
		            smallthumbs_position: 'left',
		            show_icon: false,
		            autoplay: false,
		            keyboard: false,
		            zoom_easing: false
		        });
		    }
		}
	</script>
{% endput %}

<script type="text/javascript">
var google_tag_params = {
	ecomm_prodid: "{{product.id}}",
	ecomm_pagetype: "product",
	ecomm_totalvalue: {{product.price|ratePrice }}
};
</script>
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', '125718844809609');
fbq('track', 'PageView');
fbq('track', 'ViewContent');
</script>
<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=125718844809609&ev=PageView&noscript=1"/></noscript>
<!-- DO NOT MODIFY -->
<!-- End Facebook Pixel Code -->



